package com.wan37.logic.handler.server;

import com.wan37.logic.component.Worker;
import com.wan37.protobuf.constant.AllRoleLabel;
import com.wan37.protobuf.constant.CommonBase;
import com.wan37.logic.domain.vo.MonsterVO;
import com.wan37.logic.global.reference.SpringContextHolder;
import com.wan37.logic.handler.WorkerHandler;
import com.wan37.logic.service.cache.MonsterServiceCache;
import com.wan37.logic.service.cache.SceneServiceCache;
import com.wan37.logic.utils.RouteUtils;
import com.wan37.protobuf.constant.Common;

/**
 * boss复活处理
 *
 * @author : luoyong
 * @date : 2020-06-11 17:37
 **/
public class RevertMonsterHandler implements WorkerHandler {
    private String monsterId;
    private MonsterServiceCache monsterServiceCache;
    private SceneServiceCache sceneServiceCache;
    private RouteUtils routeUtils;

    public RevertMonsterHandler(String monsterId) {
        this.monsterId = monsterId;
    }

    @Override
    public void execute(Worker worker) throws Exception {
        this.sceneServiceCache = SpringContextHolder.getBean("sceneServiceCache");
        this.monsterServiceCache = SpringContextHolder.getBean("monsterServiceCache");
        this.routeUtils = SpringContextHolder.getBean("routeUtils");
        MonsterVO monsterVO = monsterServiceCache.getMonsterServiceMap().get(monsterId).getMonsterVO();
        //怪物MP回复初始值
        monsterVO.getNumberMap().put(CommonBase.MP, monsterServiceCache.getMonsterServiceMap().
                get(monsterVO.getAllRoleId()).getBaseMp());
        monsterVO.setStatus(AllRoleLabel.STATUS_LIFE);
        routeUtils.sendAoiBroadcastResponse(Common.SERVER_MONSTER_REVERT,
                sceneServiceCache.getSceneServiceMap().get(monsterVO.getSceneId()).getUserIdSet(), monsterVO);
        System.out.println(monsterVO.toString() + "已经复活！！！");
    }
}
